/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package xmijcoltrane;

/**
 *
 * @author Felipe Gutierrez
 */


import java.util.Stack;

import net.sf.jColtrane.annotations.methods.BeforeElement;
import net.sf.jColtrane.annotations.methods.EndElement;
import net.sf.jColtrane.annotations.methods.StartElement;
import net.sf.jColtrane.handler.ContextVariables;
import net.sf.jColtrane.handler.SAXEvent;

import xmibase.XmiAbstraction;
import xmibase.XmiClass;
import xmibase.XmiInterface;
import xmibase.XmiPackage;

public class XmiGetAbstraction {
	public XmiPackage rootPackage;
	public Stack elements;
	public boolean debug = false;
	//public ArrayList<XMIGeneralization> generalizations;

	public XmiGetAbstraction(XmiPackage packages, Stack elements) {

		this.elements = elements;
		this.rootPackage = packages;

	}
	public void printDebug(String msg) {
		if (debug) {
			System.out.println(msg);
		}
	}

	@BeforeElement(elementDeep = 1, tag = "UML:ModelElement.clientDependency")
	@StartElement(tag = "UML:Abstraction")
	public void startAbstrctionClass(ContextVariables contextVariables){
		SAXEvent event = contextVariables.getLastEvent();

		printDebug("	Start Abstraction: "  + event.getAtributesHolder().getValue("xmi.id"));

		XmiClass xmiClass = (XmiClass) this.elements.peek();

		XmiAbstraction xmiAbstraction = new XmiAbstraction();

		xmiAbstraction.setId(event.getAtributesHolder().getValue("xmi.idref"));
		xmiClass.setHasInterface(true);
		xmiClass.addAbstraction(xmiAbstraction);



	}
	/**
	 * start a UML:Abstraction element of the UML:Package
	 *
	 * @param contextVariables
	 */
	@BeforeElement(elementDeep = 1, tag = "UML:Namespace.ownedElement")
	@StartElement(tag = "UML:Abstraction")
	public void startGeneralizationPackage(ContextVariables contextVariables) {
		SAXEvent event = contextVariables.getLastEvent();

		printDebug("	Start Abstraction: "  + event.getAtributesHolder().getValue("xmi.id"));

		XmiAbstraction xmiAbstraction = new XmiAbstraction();
		xmiAbstraction.setId(event.getAtributesHolder().getValue("xmi.id"));

		this.elements.push(xmiAbstraction);

	}

	/**
	 * end of the UML:Class element of the UML:Abstraction
	 *
	 * @param contextVariables
	 */
	@BeforeElement(elementDeep = 1, tag = "UML:Dependency.client")
	@StartElement(tag = "UML:Class")
	public void startClassAbstraction(ContextVariables contextVariables) {

		SAXEvent event = contextVariables.getLastEvent();

		XmiAbstraction xmiAbstraction = (XmiAbstraction) this.elements.peek();

		XmiClass xmiClass = new XmiClass();
		xmiClass.setId(event.getAtributesHolder().getValue("xmi.idref"));

		xmiAbstraction.setXmiClass(xmiClass);


	}

	@BeforeElement(elementDeep = 1, tag = "UML:Dependency.supplier")
	@StartElement(tag = "UML:Interface")
	public void startInterfaceAbstraction(
			ContextVariables contextVariables) {

		SAXEvent event = contextVariables.getLastEvent();

		XmiAbstraction xmiAbstraction = (XmiAbstraction) this.elements.peek();

		XmiInterface xmiInterface = new XmiInterface();
		xmiInterface.setId(event.getAtributesHolder().getValue("xmi.idref"));

		xmiAbstraction.setXmiInterface(xmiInterface);


	}
	/**
	 * start a UML:Abstraction element of the UML:Package
	 *
	 * @param contextVariables
	 */
	@BeforeElement(elementDeep = 1, tag = "UML:Namespace.ownedElement")
	@EndElement(tag = "UML:Abstraction")
	public void endAbstractionPackage(ContextVariables contextVariables) {
		SAXEvent event = contextVariables.getLastEvent();

		XmiAbstraction xmiAbstraction = (XmiAbstraction) this.elements.peek();
		this.elements.pop();
		this.rootPackage.addAbstraction(xmiAbstraction);
	}

}
